// localLifePackage/pages/faceCode/faceCode.js
var app = getApp();

var common = require("../../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        pagesLength: 1
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        let that = this;
        let pagesLength = getCurrentPages().length;
        var isIPX = app.globalData.isIPX;
        that.setData({
            isIPX: isIPX,
            pagesLength: pagesLength,
            domain: app.globalData.domain.slice(0, -10)
        });
        that.setData({
            money: options.money || "",
            id: options.id || "",
            name: options.name || ""
        });
        if (options.money) {
            that.getQr_money_code();
        } else {
            that.getQr_code();
        }
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    gotoUrl: function() {
        wx.navigateTo({
            url: "/localLifePackage/pages/setMoney/setMoney"
        });
    },
    getQr_money_code: function() {
        let {money: money, id: id} = this.data;
        common.request({
            endpoint: "order/face-money-qr",
            method: "post",
            data: {
                page: "localLifePackage/pages/payMoney/payMoney",
                // page:'pages/index/index',
                money: money,
                business_id: id
            },
            success: res => {
                this.setData({
                    qr: res.extra
                });
            }
        });
    },
    getQr_code: function() {
        let {id: id} = this.data;
        common.request({
            endpoint: "order/face-pay-qr",
            method: "post",
            data: {
                page: "localLifePackage/pages/payMoney/payMoney",
                // page:'pages/index/index',
                business_id: id
            },
            success: res => {
                this.setData({
                    qr: res.extra
                });
            }
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 0
        });
    }
});